package org.example.leetcode.common.pojo;

import lombok.Data;
import org.springframework.http.HttpStatus;

/**
 * GlobalResponse
 *
 * @author admin
 * @version 2023/11/28 18:15
 **/
@Data
public class GlobalResponse<T> {
    private String code;
    private T data;
    private String message;
    public GlobalResponse(String code, T data)
    {
        this.code=code;
        this.data=data;
    }
    public GlobalResponse(String code, String message)
    {
        this.code=code;
        this.message=message;
    }
    public GlobalResponse(String code, T data, String message){
        this.data=data;
        this.message=message;
        this.code=code;
    }
    public GlobalResponse(){}
    public  static  GlobalResponse success()
    {
        return new GlobalResponse(String.valueOf(HttpStatus.OK.value()), null,"成功");
    }
    public  static <T>  GlobalResponse<T> success(T data)
    {
        return new GlobalResponse(String.valueOf(HttpStatus.OK.value()),data,"成功");
    }
    public static <T> GlobalResponse<T> success(T data,String message)
    {
        return new GlobalResponse(String.valueOf(HttpStatus.OK.value()),data,message);
    }
    public static <T> GlobalResponse fail()
    {
        return new GlobalResponse(String.valueOf(HttpStatus.INTERNAL_SERVER_ERROR.value()),null,"失败");
    }
    public static <T> GlobalResponse fail(String code,String message)
    {
        return new GlobalResponse(code,null,message);
    }
    public static <T> GlobalResponse fail(String message){
        return new GlobalResponse(String.valueOf(HttpStatus.INTERNAL_SERVER_ERROR.value()),null,message);
    }


}
